using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

namespace com.yoozoo.gta.Gameplay.PVE
{
    public class NavmeshTestScene : MonoBehaviour
    {
        private List<NavmeshUnit> myUnits = new List<NavmeshUnit>();
        private List<NavmeshUnit> enemyUnits = new List<NavmeshUnit>();
        
        public static NavmeshTestScene Instance;
        
        private void Start()
        {
            Instance = this;
            myUnits.Add(GetUnit(0));
            
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
            enemyUnits.Add(GetUnit(1));
        }

        private NavmeshUnit GetUnit(int team)
        {
            var unit = new NavmeshUnit();
            unit.Init();
            unit.team = team;
            unit.attackRange = 3f;//UnityEngine.Random.Range(3f, 8f);
            unit.gameObject.transform.position = new Vector3(team == 0 ? -10:10,0,0) + new Vector3(Random.Range(-1f,1f),0,Random.Range(-1f,1f));
            unit.gameObject.name = team.ToString();
            return unit;
        }
        
        private void Update()
        {
            for (int i = 0; i < myUnits.Count; i++)
            {
                myUnits[i].Update();
            }
            for (int i = 0; i < enemyUnits.Count; i++)
            {
                enemyUnits[i].Update();
            }
        }

        public NavmeshUnit GetTarget(int team)
        {
            if (team == 0)
            {
                return enemyUnits[0];
            }

            return myUnits[0];
        }
    }
}